package com.cat.binaryTree;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-elements-in-a-contaminated-binary-tree/description/
 * @create 2025/9/30 20:43
 * @since JDK17
 */

class FindElements {
    TreeNode root;
    Set<Integer> set = new HashSet<>();
    public FindElements(TreeNode root) {
        this.root = root;
        repair(root, 0);
    }
    void repair(TreeNode root, int val) {
        if (root == null) {
            return;
        }
        set.add(val);
        root.val = val;
        repair(root.left, val * 2 + 1);
        repair(root.right, val * 2 + 2);
    }

    public boolean find(int target) {
        return set.contains(target);
    }
}
